package com.myself.ssoserver.controller

import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import java.time.LocalDateTime
import java.time.ZoneId

@RestController
@RequestMapping("/tests")
class CommonController {
    @RequestMapping("/withAuth")
    fun getAuthenticatedUser(): Long {
        val now = LocalDateTime.now(ZoneId.of("UTC")) // 以 UTC 时间计算
        val nextDrawMinutes = (now.minute / 10) * 10 + 10 // 计算下一个 10 分钟整点
        val nextDrawTime = now.withMinute(nextDrawMinutes % 60).withSecond(0).withNano(0)

        // 如果时间已经过了当前小时的 50 分钟，需要跳到下一个小时
        val adjustedDrawTime = if (nextDrawMinutes >= 60) {
            nextDrawTime.plusHours(1).withMinute(0)
        } else {
            nextDrawTime
        }

        val timestamp = adjustedDrawTime.atZone(ZoneId.of("UTC")).toInstant().toEpochMilli()

        return timestamp
    }
}